package com.tianyi.primeval.registry;

import com.google.common.base.CaseFormat;
import com.tianyi.primeval.Primeval;
import com.tianyi.primeval.entity.*;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.MobCategory;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegisterEvent;

import static com.tianyi.primeval.Primeval.MODID;


public class PLEntiteRegristrys {
    //private static final DeferredRegister<EntityType<?>> ENTITIES = DeferredRegister.create(ForgeRegistries.ENTITY_TYPES, MODID);
    public static final ResourceLocation BIGDriveLoc = new ResourceLocation(Primeval.MODID,//写完检查specialattacks文件夹是否有对应的实体
            classToString(BigDriveEnity.class));
    public static EntityType<BigDriveEnity> BIGDrive;
    public static final ResourceLocation blowingLOC = new ResourceLocation(MODID,//注意检查Enity命名
            classToString(BlowingEnity.class));
    public static EntityType<BlowingEnity> bl;
    public static final ResourceLocation WindproEnityLOC = new ResourceLocation(MODID,
            classToString(WindproEnity.class));
    public static EntityType<WindproEnity> wd;
    public static final ResourceLocation ZheSheiEnityLOC = new ResourceLocation(MODID,
            classToString(ZhesheiEnity.class));
    public static EntityType<ZhesheiEnity> zs;
    public static final ResourceLocation HuanRenLOC = new ResourceLocation(MODID,
            classToString(HuanRenEnity.class));
    public static EntityType<HuanRenEnity> hr;
    public static final ResourceLocation YingYuLOC = new ResourceLocation(MODID,
            classToString(YingYuEnity.class));
    public static EntityType<YingYuEnity> yy;
    public static final ResourceLocation SunPROLOC = new ResourceLocation(MODID,
            classToString(SumonSwordPROEntity.class));
    public static EntityType<SumonSwordPROEntity> sp;
    public static final ResourceLocation QIJILOC = new ResourceLocation(MODID,
            classToString(QiJiEnity.class));
    public static EntityType<QiJiEnity> qj;

    public static void register(RegisterEvent event) {
        event.register(ForgeRegistries.Keys.ENTITY_TYPES, helper -> {
            {
                EntityType < BigDriveEnity > entity = BIGDrive = EntityType.Builder.of(BigDriveEnity::new, MobCategory.MISC)
                        .sized(3.0F, 3.0F).setTrackingRange(4).setUpdateInterval(20)
                        .setCustomClientFactory(BigDriveEnity::createInstance).build(BIGDriveLoc.toString());
                helper.register(BIGDriveLoc, entity);
            }
        });
        event.register(ForgeRegistries.Keys.ENTITY_TYPES, helper -> {
            {
                EntityType < BlowingEnity > entity = bl = EntityType.Builder.of(BlowingEnity::new, MobCategory.MISC)
                        .sized(3.0F, 3.0F).setTrackingRange(4).setUpdateInterval(20)
                        .setCustomClientFactory(BlowingEnity::createInstance).build(blowingLOC.toString());
                helper.register(blowingLOC, entity);
            }
        });
        event.register(ForgeRegistries.Keys.ENTITY_TYPES, helper -> {
            {
                EntityType < WindproEnity > entity = wd = EntityType.Builder.of(WindproEnity::new, MobCategory.MISC)
                        .sized(3.0F, 3.0F).setTrackingRange(4).setUpdateInterval(20)
                        .setCustomClientFactory(WindproEnity::createInstance).build(WindproEnityLOC.toString());
                helper.register(WindproEnityLOC, entity);
            }
        });
        event.register(ForgeRegistries.Keys.ENTITY_TYPES, helper -> {
            {
                EntityType < ZhesheiEnity > entity = zs = EntityType.Builder.of(ZhesheiEnity::new, MobCategory.MISC)
                        .sized(3.0F, 3.0F).setTrackingRange(4).setUpdateInterval(20)
                        .setCustomClientFactory(ZhesheiEnity::createInstance).build(ZheSheiEnityLOC.toString());
                helper.register(ZheSheiEnityLOC, entity);
            }
        });
        event.register(ForgeRegistries.Keys.ENTITY_TYPES, helper -> {
            {
                EntityType < HuanRenEnity > entity = hr = EntityType.Builder.of(HuanRenEnity::new, MobCategory.MISC)
                        .sized(3.0F, 3.0F).setTrackingRange(4).setUpdateInterval(20)
                        .setCustomClientFactory(HuanRenEnity::createInstance).build(HuanRenLOC.toString());
                helper.register(HuanRenLOC, entity);
            }
        });
        event.register(ForgeRegistries.Keys.ENTITY_TYPES, helper -> {
            {
                EntityType <YingYuEnity> entity = yy = EntityType.Builder.of(YingYuEnity::new, MobCategory.MISC)
                        .sized(3.0F, 3.0F).setTrackingRange(4).setUpdateInterval(20)
                        .setCustomClientFactory(YingYuEnity::createInstance).build(YingYuLOC.toString());
                helper.register(YingYuLOC, entity);
            }
        });
        event.register(ForgeRegistries.Keys.ENTITY_TYPES, helper -> {
            {
                EntityType <SumonSwordPROEntity> entity = sp = EntityType.Builder.of(SumonSwordPROEntity::new, MobCategory.MISC)
                        .sized(3.0F, 3.0F).setTrackingRange(4).setUpdateInterval(20)
                        .setCustomClientFactory(SumonSwordPROEntity::createInstance).build(SunPROLOC.toString());
                helper.register(SunPROLOC, entity);
            }
        });
        event.register(ForgeRegistries.Keys.ENTITY_TYPES, helper -> {
            {
                EntityType <QiJiEnity> entity = qj = EntityType.Builder.of(QiJiEnity::new, MobCategory.MISC)
                        .sized(3.0F, 3.0F).setTrackingRange(4).setUpdateInterval(20)
                        .setCustomClientFactory(QiJiEnity::createInstance).build(QIJILOC.toString());
                helper.register(QIJILOC, entity);
            }
        });
    }

    public static String classToString(Class<? extends Entity> entityClass)
    {
        return CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, entityClass.getSimpleName())
                .replace("entity_", "");
    }
}
